<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>示例：Todo List | Redux 中文文档 Join the chat at https://gitter.im/camsong/redux-in-chinese</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.3.3">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-edit-link/plugin.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-prism/prism.css">
        
    
    

        
    
    
    <link rel="next" href="../../docs/advanced/index.html" />
    
    
    <link rel="prev" href="../../docs/basics/UsageWithReact.html" />
    

        
    </head>
    <body>
        
        
    <div class="book" data-level="2.6" data-basepath="../.." data-revision="Thu Mar 16 2017 23:41:56 GMT+0800 (CST)">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        

        

        
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        自述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="docs/introduction/index.html">
            
                
                    <a href="../../docs/introduction/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        介绍
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="docs/introduction/Motivation.html">
            
                
                    <a href="../../docs/introduction/Motivation.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        动机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="docs/introduction/CoreConcepts.html">
            
                
                    <a href="../../docs/introduction/CoreConcepts.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        核心概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="docs/introduction/ThreePrinciples.html">
            
                
                    <a href="../../docs/introduction/ThreePrinciples.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        三大原则
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="docs/introduction/PriorArt.html">
            
                
                    <a href="../../docs/introduction/PriorArt.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        先前技术
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="docs/introduction/Ecosystem.html">
            
                
                    <a href="../../docs/introduction/Ecosystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        生态系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="docs/introduction/Examples.html">
            
                
                    <a href="../../docs/introduction/Examples.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        示例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="docs/basics/index.html">
            
                
                    <a href="../../docs/basics/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="docs/basics/Actions.html">
            
                
                    <a href="../../docs/basics/Actions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        Action
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="docs/basics/Reducers.html">
            
                
                    <a href="../../docs/basics/Reducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        Reducer
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="docs/basics/Store.html">
            
                
                    <a href="../../docs/basics/Store.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Store
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="docs/basics/DataFlow.html">
            
                
                    <a href="../../docs/basics/DataFlow.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        数据流
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="docs/basics/UsageWithReact.html">
            
                
                    <a href="../../docs/basics/UsageWithReact.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        搭配 React
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.6" data-path="docs/basics/ExampleTodoList.html">
            
                
                    <a href="../../docs/basics/ExampleTodoList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        示例：Todo List
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="docs/advanced/index.html">
            
                
                    <a href="../../docs/advanced/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="docs/advanced/AsyncActions.html">
            
                
                    <a href="../../docs/advanced/AsyncActions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        异步 Action
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="docs/advanced/AsyncFlow.html">
            
                
                    <a href="../../docs/advanced/AsyncFlow.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        异步数据流
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="docs/advanced/Middleware.html">
            
                
                    <a href="../../docs/advanced/Middleware.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Middleware
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="docs/advanced/UsageWithReactRouter.html">
            
                
                    <a href="../../docs/advanced/UsageWithReactRouter.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        搭配 React Router
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="docs/advanced/ExampleRedditAPI.html">
            
                
                    <a href="../../docs/advanced/ExampleRedditAPI.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        示例：Reddit API
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="docs/advanced/NextSteps.html">
            
                
                    <a href="../../docs/advanced/NextSteps.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        下一步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="docs/recipes/index.html">
            
                
                    <a href="../../docs/recipes/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        技巧
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="docs/recipes/MigratingToRedux.html">
            
                
                    <a href="../../docs/recipes/MigratingToRedux.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        迁移到 Redux
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="docs/recipes/UsingObjectSpreadOperator.html">
            
                
                    <a href="../../docs/recipes/UsingObjectSpreadOperator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        使用对象展开运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="docs/recipes/ReducingBoilerplate.html">
            
                
                    <a href="../../docs/recipes/ReducingBoilerplate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        减少样板代码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="docs/recipes/ServerRendering.html">
            
                
                    <a href="../../docs/recipes/ServerRendering.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        服务端渲染
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="docs/recipes/WritingTests.html">
            
                
                    <a href="../../docs/recipes/WritingTests.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        编写测试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="docs/recipes/ComputingDerivedData.html">
            
                
                    <a href="../../docs/recipes/ComputingDerivedData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        计算衍生数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="docs/recipes/ImplementingUndoHistory.html">
            
                
                    <a href="../../docs/recipes/ImplementingUndoHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        实现撤销重做
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="docs/recipes/IsolatingSubapps.html">
            
                
                    <a href="../../docs/recipes/IsolatingSubapps.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        子应用隔离
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="docs/recipes/StructuringReducers.html">
            
                
                    <a href="../../docs/recipes/StructuringReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        组织 Reducer
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.9.1" data-path="docs/recipes/reducers/PrerequisiteConcepts.html">
            
                
                    <a href="../../docs/recipes/reducers/PrerequisiteConcepts.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.1.</b>
                        
                        Reducer 基础概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.2" data-path="docs/recipes/reducers/BasicReducerStructure.html">
            
                
                    <a href="../../docs/recipes/reducers/BasicReducerStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.2.</b>
                        
                        Reducer 基础结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.3" data-path="docs/recipes/reducers/SplittingReducerLogic.html">
            
                
                    <a href="../../docs/recipes/reducers/SplittingReducerLogic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.3.</b>
                        
                        Reducer 逻辑拆分
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.4" data-path="docs/recipes/reducers/RefactoringReducersExample.html">
            
                
                    <a href="../../docs/recipes/reducers/RefactoringReducersExample.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.4.</b>
                        
                        Reducer 重构示例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.5" data-path="docs/recipes/reducers/UsingCombineReducers.html">
            
                
                    <a href="../../docs/recipes/reducers/UsingCombineReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.5.</b>
                        
                        `combineReducers` 用法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.6" data-path="docs/recipes/reducers/BeyondCombineReducers.html">
            
                
                    <a href="../../docs/recipes/reducers/BeyondCombineReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.6.</b>
                        
                        `combineReducers` 进阶
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.7" data-path="docs/recipes/reducers/NormalizingStateShape.html">
            
                
                    <a href="../../docs/recipes/reducers/NormalizingStateShape.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.7.</b>
                        
                        State 范式化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.8" data-path="docs/recipes/reducers/UpdatingNormalizedData.html">
            
                
                    <a href="../../docs/recipes/reducers/UpdatingNormalizedData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.8.</b>
                        
                        管理范式化数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.9" data-path="docs/recipes/reducers/ReusingReducerLogic.html">
            
                
                    <a href="../../docs/recipes/reducers/ReusingReducerLogic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.9.</b>
                        
                        Reducer 逻辑复用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.10" data-path="docs/recipes/reducers/ImmutableUpdatePatterns.html">
            
                
                    <a href="../../docs/recipes/reducers/ImmutableUpdatePatterns.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.10.</b>
                        
                        不可变更新模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.11" data-path="docs/recipes/reducers/InitializingState.html">
            
                
                    <a href="../../docs/recipes/reducers/InitializingState.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.11.</b>
                        
                        初始化 State
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="docs/FAQ.html">
            
                
                    <a href="../../docs/FAQ.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        常见问题
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="docs/faq/General.html">
            
                
                    <a href="../../docs/faq/General.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        综合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="docs/faq/Reducers.html">
            
                
                    <a href="../../docs/faq/Reducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Reducer
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="docs/faq/OrganizingState.html">
            
                
                    <a href="../../docs/faq/OrganizingState.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        组织 State
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="docs/faq/StoreSetup.html">
            
                
                    <a href="../../docs/faq/StoreSetup.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        创建 Store
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="docs/faq/Actions.html">
            
                
                    <a href="../../docs/faq/Actions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        Action
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="docs/faq/CodeStructure.html">
            
                
                    <a href="../../docs/faq/CodeStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        代码结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="docs/faq/Performance.html">
            
                
                    <a href="../../docs/faq/Performance.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        性能
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="docs/faq/ReactRedux.html">
            
                
                    <a href="../../docs/faq/ReactRedux.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        React Redux
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="docs/faq/Miscellaneous.html">
            
                
                    <a href="../../docs/faq/Miscellaneous.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        其它
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="docs/Troubleshooting.html">
            
                
                    <a href="../../docs/Troubleshooting.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        排错
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="docs/Glossary.html">
            
                
                    <a href="../../docs/Glossary.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        词汇表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="docs/api/index.html">
            
                
                    <a href="../../docs/api/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        API 文档
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="docs/api/createStore.html">
            
                
                    <a href="../../docs/api/createStore.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        createStore
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="docs/api/Store.html">
            
                
                    <a href="../../docs/api/Store.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        Store
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="docs/api/combineReducers.html">
            
                
                    <a href="../../docs/api/combineReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        combineReducers
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="docs/api/applyMiddleware.html">
            
                
                    <a href="../../docs/api/applyMiddleware.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        applyMiddleware
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="docs/api/bindActionCreators.html">
            
                
                    <a href="../../docs/api/bindActionCreators.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        bindActionCreators
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="docs/api/compose.html">
            
                
                    <a href="../../docs/api/compose.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        compose
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="docs/react-redux/index.html">
            
                
                    <a href="../../docs/react-redux/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        react-redux 文档
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="docs/react-redux/api.html">
            
                
                    <a href="../../docs/react-redux/api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        API
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="docs/react-redux/troubleshooting.html">
            
                
                    <a href="../../docs/react-redux/troubleshooting.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        排错
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" >
            
                
                    <a target="_blank" href="https:/github.com/react-guide/redux-tutorial-cn">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        redux-tutorial
                    </a>
            
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                Published with GitBook
            </a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Table of Contents"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Font Settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Share"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    Share on Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    Share on Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    Share on Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    Share on Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    Share on Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Redux 中文文档 Join the chat at https://gitter.im/camsong/redux-in-chinese</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <a id="edit-link" href="https://github.com/camsong/redux-in-chinese/tree/master/docs/basics/ExampleTodoList.md" class="btn fa fa-edit pull-left">&#xA0;&#xA0;&#x5F00;&#x59CB;&#x7EA0;&#x9519;</a><h1 id="%E7%A4%BA%E4%BE%8B-todo-%E5%88%97%E8%A1%A8">&#x793A;&#x4F8B;: Todo &#x5217;&#x8868;</h1>
<p>&#x8FD9;&#x662F;&#x6211;&#x4EEC;&#x5728;<a href="index.html">&#x57FA;&#x7840;&#x6559;&#x7A0B;</a>&#x91CC;&#x5F00;&#x53D1;&#x7684;&#x8FF7;&#x4F60;&#x578B;&#x7684;&#x4EFB;&#x52A1;&#x7BA1;&#x7406;&#x5E94;&#x7528;&#x7684;&#x5B8C;&#x6574;&#x6E90;&#x7801;&#x3002;</p>
<h2 id="%E5%85%A5%E5%8F%A3%E6%96%87%E4%BB%B6">&#x5165;&#x53E3;&#x6587;&#x4EF6;</h2>
<h4 id="-index-js"><code>index<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token keyword">import</span> React from <span class="token string">&apos;react&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> render <span class="token punctuation">}</span> from <span class="token string">&apos;react-dom&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> createStore <span class="token punctuation">}</span> from <span class="token string">&apos;redux&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> Provider <span class="token punctuation">}</span> from <span class="token string">&apos;react-redux&apos;</span>
<span class="token keyword">import</span> App from <span class="token string">&apos;./containers/App&apos;</span>
<span class="token keyword">import</span> todoApp from <span class="token string">&apos;./reducers&apos;</span>

<span class="token keyword">let</span> store <span class="token operator">=</span> <span class="token function">createStore</span><span class="token punctuation">(</span>todoApp<span class="token punctuation">)</span>

<span class="token keyword">let</span> rootElement <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">&apos;root&apos;</span><span class="token punctuation">)</span>
<span class="token function">render</span><span class="token punctuation">(</span>
  <span class="token operator">&lt;</span>Provider store<span class="token operator">=</span><span class="token punctuation">{</span>store<span class="token punctuation">}</span><span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>App <span class="token operator">/</span><span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>Provider<span class="token operator">&gt;</span><span class="token punctuation">,</span>
  rootElement
<span class="token punctuation">)</span>
</code></pre>
<h2 id="action-%E5%88%9B%E5%BB%BA%E5%87%BD%E6%95%B0%E5%92%8C%E5%B8%B8%E9%87%8F">Action &#x521B;&#x5EFA;&#x51FD;&#x6570;&#x548C;&#x5E38;&#x91CF;</h2>
<h4 id="-actions-js"><code>actions<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token comment" spellcheck="true">/*
 * action &#x7C7B;&#x578B;
 */</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> ADD_TODO <span class="token operator">=</span> <span class="token string">&apos;ADD_TODO&apos;</span><span class="token punctuation">;</span>
<span class="token keyword">export</span> <span class="token keyword">const</span> COMPLETE_TODO <span class="token operator">=</span> <span class="token string">&apos;COMPLETE_TODO&apos;</span><span class="token punctuation">;</span>
<span class="token keyword">export</span> <span class="token keyword">const</span> SET_VISIBILITY_FILTER <span class="token operator">=</span> <span class="token string">&apos;SET_VISIBILITY_FILTER&apos;</span>

<span class="token comment" spellcheck="true">/*
 * &#x5176;&#x5B83;&#x7684;&#x5E38;&#x91CF;
 */</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> VisibilityFilters <span class="token operator">=</span> <span class="token punctuation">{</span>
  SHOW_ALL<span class="token punctuation">:</span> <span class="token string">&apos;SHOW_ALL&apos;</span><span class="token punctuation">,</span>
  SHOW_COMPLETED<span class="token punctuation">:</span> <span class="token string">&apos;SHOW_COMPLETED&apos;</span><span class="token punctuation">,</span>
  SHOW_ACTIVE<span class="token punctuation">:</span> <span class="token string">&apos;SHOW_ACTIVE&apos;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">/*
 * action &#x521B;&#x5EFA;&#x51FD;&#x6570;
 */</span>

<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">addTodo</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">{</span> type<span class="token punctuation">:</span> ADD_TODO<span class="token punctuation">,</span> text <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">completeTodo</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">{</span> type<span class="token punctuation">:</span> COMPLETE_TODO<span class="token punctuation">,</span> index <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">setVisibilityFilter</span><span class="token punctuation">(</span>filter<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">{</span> type<span class="token punctuation">:</span> SET_VISIBILITY_FILTER<span class="token punctuation">,</span> filter <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="reducers">Reducers</h2>
<h4 id="-reducers-js"><code>reducers<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token keyword">import</span> <span class="token punctuation">{</span> combineReducers <span class="token punctuation">}</span> from <span class="token string">&apos;redux&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> ADD_TODO<span class="token punctuation">,</span> COMPLETE_TODO<span class="token punctuation">,</span> SET_VISIBILITY_FILTER<span class="token punctuation">,</span> VisibilityFilters <span class="token punctuation">}</span> from <span class="token string">&apos;./actions&apos;</span>
<span class="token keyword">const</span> <span class="token punctuation">{</span> SHOW_ALL <span class="token punctuation">}</span> <span class="token operator">=</span> VisibilityFilters

<span class="token keyword">function</span> <span class="token function">visibilityFilter</span><span class="token punctuation">(</span>state <span class="token operator">=</span> SHOW_ALL<span class="token punctuation">,</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">switch</span> <span class="token punctuation">(</span>action<span class="token punctuation">.</span>type<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">case</span> SET_VISIBILITY_FILTER<span class="token punctuation">:</span>
      <span class="token keyword">return</span> action<span class="token punctuation">.</span>filter
    <span class="token keyword">default</span><span class="token punctuation">:</span>
      <span class="token keyword">return</span> state
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">function</span> <span class="token function">todos</span><span class="token punctuation">(</span>state <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> action<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">switch</span> <span class="token punctuation">(</span>action<span class="token punctuation">.</span>type<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">case</span> ADD_TODO<span class="token punctuation">:</span>
      <span class="token keyword">return</span> <span class="token punctuation">[</span>
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>state<span class="token punctuation">,</span>
        <span class="token punctuation">{</span>
          text<span class="token punctuation">:</span> action<span class="token punctuation">.</span>text<span class="token punctuation">,</span>
          completed<span class="token punctuation">:</span> <span class="token keyword">false</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">]</span>
    <span class="token keyword">case</span> COMPLETE_TODO<span class="token punctuation">:</span>
      <span class="token keyword">return</span> <span class="token punctuation">[</span>
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> action<span class="token punctuation">.</span>index<span class="token punctuation">)</span><span class="token punctuation">,</span>
        Object<span class="token punctuation">.</span><span class="token function">assign</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> state<span class="token punctuation">[</span>action<span class="token punctuation">.</span>index<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
          completed<span class="token punctuation">:</span> <span class="token keyword">true</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span>action<span class="token punctuation">.</span>index <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span>
      <span class="token punctuation">]</span>
    <span class="token keyword">default</span><span class="token punctuation">:</span>
      <span class="token keyword">return</span> state
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">const</span> todoApp <span class="token operator">=</span> <span class="token function">combineReducers</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  visibilityFilter<span class="token punctuation">,</span>
  todos
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> todoApp
</code></pre>
<h2 id="%E5%AE%B9%E5%99%A8%E7%BB%84%E4%BB%B6">&#x5BB9;&#x5668;&#x7EC4;&#x4EF6;</h2>
<h4 id="-containers-app-js"><code>containers<span class="token operator">/</span>App<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span> Component<span class="token punctuation">,</span> PropTypes <span class="token punctuation">}</span> from <span class="token string">&apos;react&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> connect <span class="token punctuation">}</span> from <span class="token string">&apos;react-redux&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> addTodo<span class="token punctuation">,</span> completeTodo<span class="token punctuation">,</span> setVisibilityFilter<span class="token punctuation">,</span> VisibilityFilters <span class="token punctuation">}</span> from <span class="token string">&apos;../actions&apos;</span>
<span class="token keyword">import</span> AddTodo from <span class="token string">&apos;../components/AddTodo&apos;</span>
<span class="token keyword">import</span> TodoList from <span class="token string">&apos;../components/TodoList&apos;</span>
<span class="token keyword">import</span> Footer from <span class="token string">&apos;../components/Footer&apos;</span>

<span class="token keyword">class</span> <span class="token class-name">App</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">// Injected by connect() call:</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span> dispatch<span class="token punctuation">,</span> visibleTodos<span class="token punctuation">,</span> visibilityFilter <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props
    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>AddTodo
          onAddClick<span class="token operator">=</span><span class="token punctuation">{</span>text <span class="token operator">=</span><span class="token operator">&gt;</span>
            <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token function">addTodo</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">)</span>
          <span class="token punctuation">}</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>TodoList
          todos<span class="token operator">=</span><span class="token punctuation">{</span>visibleTodos<span class="token punctuation">}</span>
          onTodoClick<span class="token operator">=</span><span class="token punctuation">{</span>index <span class="token operator">=</span><span class="token operator">&gt;</span>
            <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token function">completeTodo</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span><span class="token punctuation">)</span>
          <span class="token punctuation">}</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>Footer
          filter<span class="token operator">=</span><span class="token punctuation">{</span>visibilityFilter<span class="token punctuation">}</span>
          onFilterChange<span class="token operator">=</span><span class="token punctuation">{</span>nextFilter <span class="token operator">=</span><span class="token operator">&gt;</span>
            <span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token function">setVisibilityFilter</span><span class="token punctuation">(</span>nextFilter<span class="token punctuation">)</span><span class="token punctuation">)</span>
          <span class="token punctuation">}</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
      <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

App<span class="token punctuation">.</span>propTypes <span class="token operator">=</span> <span class="token punctuation">{</span>
  visibleTodos<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span><span class="token function">arrayOf</span><span class="token punctuation">(</span>PropTypes<span class="token punctuation">.</span><span class="token function">shape</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    text<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>string<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
    completed<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>bool<span class="token punctuation">.</span>isRequired
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span>isRequired<span class="token punctuation">)</span><span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
  visibilityFilter<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span><span class="token function">oneOf</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
    <span class="token string">&apos;SHOW_ALL&apos;</span><span class="token punctuation">,</span>
    <span class="token string">&apos;SHOW_COMPLETED&apos;</span><span class="token punctuation">,</span>
    <span class="token string">&apos;SHOW_ACTIVE&apos;</span>
  <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">.</span>isRequired
<span class="token punctuation">}</span>

<span class="token keyword">function</span> <span class="token function">selectTodos</span><span class="token punctuation">(</span>todos<span class="token punctuation">,</span> filter<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">switch</span> <span class="token punctuation">(</span>filter<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">case</span> VisibilityFilters<span class="token punctuation">.</span>SHOW_ALL<span class="token punctuation">:</span>
      <span class="token keyword">return</span> todos
    <span class="token keyword">case</span> VisibilityFilters<span class="token punctuation">.</span>SHOW_COMPLETED<span class="token punctuation">:</span>
      <span class="token keyword">return</span> todos<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>todo <span class="token operator">=</span><span class="token operator">&gt;</span> todo<span class="token punctuation">.</span>completed<span class="token punctuation">)</span>
    <span class="token keyword">case</span> VisibilityFilters<span class="token punctuation">.</span>SHOW_ACTIVE<span class="token punctuation">:</span>
      <span class="token keyword">return</span> todos<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>todo <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token operator">!</span>todo<span class="token punctuation">.</span>completed<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// Which props do we want to inject, given the global state?</span>
<span class="token comment" spellcheck="true">// Note: use https://github.com/faassen/reselect for better performance.</span>
<span class="token keyword">function</span> <span class="token function">select</span><span class="token punctuation">(</span>state<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">{</span>
    visibleTodos<span class="token punctuation">:</span> <span class="token function">selectTodos</span><span class="token punctuation">(</span>state<span class="token punctuation">.</span>todos<span class="token punctuation">,</span> state<span class="token punctuation">.</span>visibilityFilter<span class="token punctuation">)</span><span class="token punctuation">,</span>
    visibilityFilter<span class="token punctuation">:</span> state<span class="token punctuation">.</span>visibilityFilter
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// &#x5305;&#x88C5; component &#xFF0C;&#x6CE8;&#x5165; dispatch &#x548C; state &#x5230;&#x5176;&#x9ED8;&#x8BA4;&#x7684; connect(select)(App) &#x4E2D;&#xFF1B;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token function">connect</span><span class="token punctuation">(</span>select<span class="token punctuation">)</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span>
</code></pre>
<h2 id="%E5%B1%95%E7%A4%BA%E7%BB%84%E4%BB%B6">&#x5C55;&#x793A;&#x7EC4;&#x4EF6;</h2>
<h4 id="-components-addtodo-js"><code>components<span class="token operator">/</span>AddTodo<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span> Component<span class="token punctuation">,</span> PropTypes <span class="token punctuation">}</span> from <span class="token string">&apos;react&apos;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">class</span> <span class="token class-name">AddTodo</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>input type<span class="token operator">=</span><span class="token string">&apos;text&apos;</span> ref<span class="token operator">=</span><span class="token string">&apos;input&apos;</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>button onClick<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">handleClick</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token operator">&gt;</span>
          Add
        <span class="token operator">&lt;</span><span class="token operator">/</span>button<span class="token operator">&gt;</span>
      <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token function">handleClick</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> node <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>refs<span class="token punctuation">.</span>input
    <span class="token keyword">const</span> text <span class="token operator">=</span> node<span class="token punctuation">.</span>value<span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span><span class="token function">onAddClick</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span>
    node<span class="token punctuation">.</span>value <span class="token operator">=</span> <span class="token string">&apos;&apos;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

AddTodo<span class="token punctuation">.</span>propTypes <span class="token operator">=</span> <span class="token punctuation">{</span>
  onAddClick<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>func<span class="token punctuation">.</span>isRequired
<span class="token punctuation">}</span>
</code></pre>
<h4 id="-components-footer-js"><code>components<span class="token operator">/</span>Footer<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span> Component<span class="token punctuation">,</span> PropTypes <span class="token punctuation">}</span> from <span class="token string">&apos;react&apos;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">class</span> <span class="token class-name">Footer</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  <span class="token function">renderFilter</span><span class="token punctuation">(</span>filter<span class="token punctuation">,</span> name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>filter <span class="token operator">===</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>filter<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> name
    <span class="token punctuation">}</span>

    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token operator">&lt;</span>a href<span class="token operator">=</span><span class="token string">&apos;#&apos;</span> onClick<span class="token operator">=</span><span class="token punctuation">{</span>e <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
        e<span class="token punctuation">.</span><span class="token function">preventDefault</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span><span class="token function">onFilterChange</span><span class="token punctuation">(</span>filter<span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator">&gt;</span>
        <span class="token punctuation">{</span>name<span class="token punctuation">}</span>
      <span class="token operator">&lt;</span><span class="token operator">/</span>a<span class="token operator">&gt;</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token operator">&lt;</span>p<span class="token operator">&gt;</span>
        Show<span class="token punctuation">:</span>
        <span class="token punctuation">{</span><span class="token string">&apos; &apos;</span><span class="token punctuation">}</span>
        <span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">renderFilter</span><span class="token punctuation">(</span><span class="token string">&apos;SHOW_ALL&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;All&apos;</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
        <span class="token punctuation">{</span><span class="token string">&apos;, &apos;</span><span class="token punctuation">}</span>
        <span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">renderFilter</span><span class="token punctuation">(</span><span class="token string">&apos;SHOW_COMPLETED&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;Completed&apos;</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
        <span class="token punctuation">{</span><span class="token string">&apos;, &apos;</span><span class="token punctuation">}</span>
        <span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">renderFilter</span><span class="token punctuation">(</span><span class="token string">&apos;SHOW_ACTIVE&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;Active&apos;</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
        <span class="token punctuation">.</span>
      <span class="token operator">&lt;</span><span class="token operator">/</span>p<span class="token operator">&gt;</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

Footer<span class="token punctuation">.</span>propTypes <span class="token operator">=</span> <span class="token punctuation">{</span>
  onFilterChange<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>func<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
  filter<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span><span class="token function">oneOf</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
    <span class="token string">&apos;SHOW_ALL&apos;</span><span class="token punctuation">,</span>
    <span class="token string">&apos;SHOW_COMPLETED&apos;</span><span class="token punctuation">,</span>
    <span class="token string">&apos;SHOW_ACTIVE&apos;</span>
  <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">.</span>isRequired
<span class="token punctuation">}</span>
</code></pre>
<h4 id="-components-todo-js"><code>components<span class="token operator">/</span>Todo<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span> Component<span class="token punctuation">,</span> PropTypes <span class="token punctuation">}</span> from <span class="token string">&apos;react&apos;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">class</span> <span class="token class-name">Todo</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token operator">&lt;</span>li
        onClick<span class="token operator">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>onClick<span class="token punctuation">}</span>
        style<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>
          textDecoration<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>completed <span class="token operator">?</span> <span class="token string">&apos;line-through&apos;</span> <span class="token punctuation">:</span> <span class="token string">&apos;none&apos;</span><span class="token punctuation">,</span>
          cursor<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>completed <span class="token operator">?</span> <span class="token string">&apos;default&apos;</span> <span class="token punctuation">:</span> <span class="token string">&apos;pointer&apos;</span>
        <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator">&gt;</span>
        <span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>text<span class="token punctuation">}</span>
      <span class="token operator">&lt;</span><span class="token operator">/</span>li<span class="token operator">&gt;</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

Todo<span class="token punctuation">.</span>propTypes <span class="token operator">=</span> <span class="token punctuation">{</span>
  onClick<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>func<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
  text<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>string<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
  completed<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>bool<span class="token punctuation">.</span>isRequired
<span class="token punctuation">}</span>
</code></pre>
<h4 id="-components-todolist-js"><code>components<span class="token operator">/</span>TodoList<span class="token punctuation">.</span>js</code></h4>
<pre><code class="lang-js"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span> Component<span class="token punctuation">,</span> PropTypes <span class="token punctuation">}</span> from <span class="token string">&apos;react&apos;</span>
<span class="token keyword">import</span> Todo from <span class="token string">&apos;./Todo&apos;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">class</span> <span class="token class-name">TodoList</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token operator">&lt;</span>ul<span class="token operator">&gt;</span>
        <span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>todos<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span>todo<span class="token punctuation">,</span> index<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
          <span class="token operator">&lt;</span>Todo <span class="token punctuation">{</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>todo<span class="token punctuation">}</span>
                key<span class="token operator">=</span><span class="token punctuation">{</span>index<span class="token punctuation">}</span>
                onClick<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span><span class="token function">onTodoClick</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span><span class="token punctuation">}</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
        <span class="token punctuation">)</span><span class="token punctuation">}</span>
      <span class="token operator">&lt;</span><span class="token operator">/</span>ul<span class="token operator">&gt;</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

TodoList<span class="token punctuation">.</span>propTypes <span class="token operator">=</span> <span class="token punctuation">{</span>
  onTodoClick<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>func<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
  todos<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span><span class="token function">arrayOf</span><span class="token punctuation">(</span>PropTypes<span class="token punctuation">.</span><span class="token function">shape</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    text<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>string<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
    completed<span class="token punctuation">:</span> PropTypes<span class="token punctuation">.</span>bool<span class="token punctuation">.</span>isRequired
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span>isRequired<span class="token punctuation">)</span><span class="token punctuation">.</span>isRequired
<span class="token punctuation">}</span>
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../docs/basics/UsageWithReact.html" class="navigation navigation-prev " aria-label="Previous page: 搭配 React"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../docs/advanced/index.html" class="navigation navigation-next " aria-label="Next page: 高级"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-edit-link/plugin.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-ga/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2},"edit-link":{"base":"https://github.com/camsong/redux-in-chinese/tree/master","label":"开始纠错"},"ga":{"token":"UA-66122997-1","configuration":"auto"}};
    gitbook.start(config);
});
</script>

        <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-66122997-1', 'auto');ga('send', 'pageview');</script>
    </body>
    
</html>
